import 'package:flutter/material.dart';
import 'package:hello_flutter/provider_demo/provider/theme_provider.dart';
import 'package:hello_flutter/provider_demo/provider/user_provider.dart';
import 'second_page.dart';
import 'package:provider/provider.dart';


class FirstPage extends StatelessWidget{

  bool onOrOff = false;
  double slideVal = 0.1;
  @override
  Widget build(BuildContext context){
    return Scaffold(
      appBar: AppBar(
        title: Text("Page One", style: Theme.of(context).textTheme.headline6),
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            Text("-- content in page One"),
            Consumer<UserProvider>(
                builder: (_, provider, __) {
                  if (provider.name != null) {
                    return Row(
                        children:<Widget>[
                          Text("hello " + provider.name),
                          FlatButton(
                            onPressed: (){provider.setName(null);},
                            child: Text("注销")
                          ),
                        ]
                    );
                  } else {
                    return Row(
                        children:<Widget>[
                          FlatButton(
                              onPressed: (){
                                Navigator.push(context, MaterialPageRoute(builder: (context) {
                                  return SecondPage();
                                }));
                              },
                              child: Text("去登录")
                          ),
                        ]
                    );
                  }
                }),
            Center(
              child: RaisedButton(
                onPressed: () {},
                child: Text("主题按钮"),
                padding: EdgeInsets.all(10),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                ),
                // 使用主题色
                color: Theme.of(context).primaryColor,
//              textColor: Colors.white,
                splashColor: Theme.of(context).splashColor,
                highlightColor: Theme.of(context).accentColor,
              ),
            ),
            Divider(),
            Center(
              child: FlatButton(
                onPressed: (){},
                child: Text("扁平按钮"),
                color: Colors.blue,
                textColor: Colors.black,
              )
            ),
          Center(
              child: OutlineButton(
                onPressed: (){ },
                child: Text("线框按钮"),
                textColor: Colors.red,
                splashColor: Colors.green,
                highlightColor: Colors.black,
              )
          ),
          Center(
              child: IconButton(
                icon: Icon(Icons.home),
                onPressed: (){},
//                color: Colors.blueAccent,
//                highlightColor: Colors.red,
              )
          ),
            Row(
                children: <Widget>[
                  Text("深色主题:"),
                  Consumer<ThemeProvider>(
                      builder: (_, provider, __) {
                        return Switch(
                            value: provider.themeMode == ThemeMode.dark,
                            onChanged: (v) {
                              print("onChanged");
                              provider.change();
                            }
                        );
                      }),
                  ]
            ),
            Center(
                child: Slider(
                    value: slideVal,
                    onChanged: (v){
                      slideVal = v;
                    }
                )
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {  },),
    );
  }
}